﻿using MediatR;
using Return.Enum;
using SlaughterItem.Common.Infrastructures.Interfaces;
using THE_WIND_RISES.Common.Domans.BasicInformation.MainPlans;
using THE_WIND_RISES.Common.Dtos;

namespace Enterprise_Set.API.Application.Commands.Week2.Mainplan_CRUD
{
    /// <summary>
    /// 删除主生产计划
    /// </summary>
    public class DelMainplanHander : IRequestHandler<DelMainplanCommand, Result>
    {
        public DelMainplanHander(IBaseRepository<Mainpalan> mainpalanRepository)
        {
            MainpalanRepository = mainpalanRepository;
        }

        public IBaseRepository<Mainpalan> MainpalanRepository { get; set; }
        public async Task<Result> Handle(DelMainplanCommand request, CancellationToken cancellationToken)
        {
            var result= new Result() { Code=(int)CommonErrorCodes.Delete};
            var sql = "update mainpalans set IsDelete=true where MainplanId=@MainplanId;";
            var DelNum = MainpalanRepository.Delete(sql, new
            {
                MainplanId=request.MainplanId,
            });
            if (DelNum > 0)
            {
                result.Code = (int)CommonErrorCodes.Success;
                return result;
            }
            else
            {
                return result;
            }
        }
    }
}
